<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        //1 利用构造函数 对象创建
        function Star(name,age,sex) {
            this.name=name;
            this.age=age;
            this.sex=sex;
            this.sayHi=function () {
                console.log('hello');
            }
        }

        //2 对象遍历
        var obj=new Star("刘德华",18,"男");
        for(var k in obj){
            console.log(k);  // 输出属性名
            console.log(obj[k]); //输出属性值
        }
    </script>
</body>
</html>